<template>
	<view class="container">
		<form class="form-warp" @submit="formSubmit">
			<view class="input-group">
				<view class="account">服务器地址</view>
				<input class="uni-input" v-model="address" name="address" placeholder="请输入服务器地址" />
			</view>
			<view class="input-group">
				<view class="textSize">端口</view>
				<input class="uni-input" v-model="port" type="number" name="port" placeholder="请输入端口" />
			</view>
			<button style="margin-top: 60px;" class="uni-button" form-type="submit" type="primary">保存</button>
		</form>
	</view>
</template>

<script>
	var that;
	export default {
		data() {
			return {
				address: '',
				port: '',
			}
		},
		onLoad() {
			that = this;
			let {
				apiUrl,
				apiPort,
				apiUrlWeb,
				apiPortWeb
			} = that.$sys.getSysInfo();
			console.log('apiUrl',apiUrl)
			console.log('apiPort',apiPort)
			this.address = apiUrl;
			this.port = apiPort;
			
			that.$util.setPageTitle(`服务器配置`)
		},
		methods: {
			formSubmit(e) {
				var formdata = e.detail.value;
				if (that.validate(formdata)) {
					that.$sys.setServer({
						url: formdata.address,
						port: formdata.port,
					});
					that.$util.showToast('修改成功', () => {
						that.$util.navigateBack(1);
					});
				}
			},
			validate(formdata) {
				if (!that.$util.validate(formdata.address, '服务器地址不能为空')) return false;
				if (!that.$util.validate(formdata.port, '端口不能为空')) return false;
				return true;
			}
		}
	}
</script>

<style>
	@import url("index.css");
</style>
